<template>
  <div class="warpper-box invoiceExamine">
    <a-card style="margin-top: 10px;">
      <form-create v-model="params.fApi" :rule="params.rule" :option="params.option" @btn-search-click="loadTable(true)"
      @btn-reset-click="reset" />
        <a-table :columns="table.columns" :data-source="table.loadData" :pagination="table.pagination"
          @change="handleTableChange" rowKey="enterpriseId">
          <!-- 操作栏-->
          <span slot="action" slot-scope="text, record" v-if="params.invoiceStatus !== '0'">
            <!-- 编辑模块 | 字段 -->
            <a @click="goDetail(record)">详情</a>
          </span>
        </a-table>
    </a-card>
  </div>
</template>

<script>
import store from '@/store'
import EnterpriseSelect from "@/components/human/enterpriseSelect.vue"
import {
  OPTION_BLOCK,
  OPTION_INLINE
} from "../base_form"
import {
  PARAMS_EXAMINE,
  COLUMNS_EXAMINE
} from "./form"
import {
  pageInvoiceStatistics
} from "@/api/human/finance"
import {
  checkRepeat
} from "@/utils/util"
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'invoiceExamine',
  components: {

  },
  data() {
    return {
      createDate: [],
      params: {
        fApi: {},
        rule: PARAMS_EXAMINE,
        option: OPTION_INLINE
      },
      table: {
        columns: COLUMNS_EXAMINE,
        loadData: [],
        pagination: {
          current: 1,
          pageSize: 10,
          total: 0,
          showSizeChanger: true,
					showQuickJumper: true,
          pageSizeOptions: ["10", "20", "50", "100"],
          showTotal: total => `共有 ${total} 条数据`,
        }
      },
      pagination: { current: 1, pageSize: 10 },

      enterpriseId: "", // 企业id
      enterpriseName: "", // 企业名称
      enterpriseData: [], // 客户列表

      selectedRowKeys: [], // 选择的table数据id
      selectedRows: [], // 选择的table数据
    }
  },
  filters: {
    filterMore(value, num) {
      if (!value) return ''
      if (value.length > num) {
        return value.slice(0, num) + '...'
      }
      return value
    }
  },
  mounted() {
    window.addEventListener('keyup', this.keyDown);
    this.loadTable(true);
  },
  destroyed() {
    window.removeEventListener('keyup', this.keyDown);
  },
  beforeCreate() {
    this.events_form = this.$form.createForm(this, {
      name: 'events_form'
    })
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  methods: {
    // table复选框选择
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows
    },
    tabsChange(e) {
      if (e == '0') {
        this.params.orderName = '';
        this.params.orderId = '';
      } else {
        this.params.startInvoiceApplyTime = undefined;
        this.params.endInvoiceApplyTime = undefined;
        this.params.invoiceId = "";
      }
      this.table.loadData = [];
      this.loadTable(true);
    },
    // 获取列表
    async loadTable(flag) {
      let params = this.params.fApi.formData();
      this.selectedRowKeys = [];
      this.selectedRows = [];
      if (flag) {
        this.table.pagination.current = 1;
        this.table.pagination.pageSize = 10;
      }
      params.pageNum = this.table.pagination.current;
      params.pageSize = this.table.pagination.pageSize;
      const { code, data } = await pageInvoiceStatistics(params);
      if (code === '1') {
        this.table.loadData = data.content;
        this.table.pagination.total = data.total || 0;
      }
    },
    handleTableChange(pagination) {
      this.table.pagination.current = pagination.current;
      this.table.pagination.pageSize = pagination.pageSize;
      this.loadTable(false);
    },
    // 跳转详情
    goDetail(row) {
      this.$router.push({ name: 'humanResourcesInvoiceExamineDetailCode', query: { enterpriseId: row.enterpriseId } });
    },
    addLoad() {
      this.loadTable(true);
    },
    reset() {
      this.params.fApi.resetFields();
      this.loadTable(true);
    }
  }
}
</script>
<style lang="less"></style>